<template>
    <view style="height: 100%">
        <view :style="'padding-top:' + (navTop * 2 - 6) + 'rpx;background:' + bgc + ';position:' + position + ';'" class="pots">
            <view class="back-img" @tap="goBack" v-if="show == 1">
                <image mode="aspectFill"  referrerPolicy='no-referrer' :src="img == 1 ? 'https://wx.xtwaixie.com/img/back1.png' : 'https://wx.xtwaixie.com/img/back2.png'"></image>
            </view>
            <view class="top-title" :style="'color: ' + color + ';'">{{ title }}</view>
        </view>
        <view :style="'padding-top:' + (navTop * 2 - 6) + 'rpx;height:90rpx;'"></view>
    </view>
</template>

<script>
const app = getApp();
export default {
    data() {
        return {
            navTop: '',
            backMy: false
        };
    },
    /**
     * 组件的属性列表
     */
    props: {
        title: {
            type: String,
            default: '标题'
        },
        img: {
            type: String,
            default: '1'
        },
        bgc: {
            type: String,
            default: '#fff'
        },
        color: {
            type: String,
            default: '#333'
        },
        deltas: {
            type: Number,
            default: 1
        },
        show: {
            type: Number,
            default: 1
        },
        homes: {
            type: Number,
            default: 1
        },
        position: {
            type: String,
            default: 'fixed'
        },
        backurl: {
            type: String,
            default: '/pages/home/home'
        }
    },
    mounted() {
        // 处理小程序 ready 生命周期
        this.$nextTick(() => this.ready());
    },
    methods: {
        ready() {
            this.navTop = app.globalData.navTop
            this.getPages();
        },

        goBack() {
            if (this.homes == 2) {
                uni.reLaunch({
                    url: '/pages/home/home'
                });
            } else {
                if (this.backMy) {
                    uni.redirectTo({
                        url: '/pages/my/my'
                    });
                    return;
                }
                uni.navigateBack({
                    delta: this.deltas
                });
            }
        },

        goHome() {
            uni.switchTab({
                url: '/pages/home/home'
            });
        },

        getPages() {
            const pages = getCurrentPages();
            if (pages.length == 1 && pages[0].route == 'pages/recharge/recharge') {
                this.backMy = true;
            }
        }
    },
    created() {}
};
</script>
<style>
@import './top.css';
</style>
